package com.myapp.RN;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.facebook.react.ReactActivity;
import com.myapp.MainApplication;

public class DeviceActivity extends ReactActivity {
    // 数据点"SystemPower"对应的存储数据
    private static boolean data_SystemPower;
    // 数据点"SystemFan"对应的存储数据
    private static boolean data_SystemFan;
    // 数据点"ErrorImfor"对应的存储数据
    private static int data_ErrorImfor;
    // 数据点"RoomTemp"对应的存储数据
    private static int data_RoomTemp;
    // 数据点"SaunaRunTime"对应的存储数据
    private static int data_SaunaRunTime;
    // 数据点"SystemLight"对应的存储数据
    private static byte[] data_SystemLight;
    // 数据点"SaunaStateTimeTemp"对应的存储数据
    private static byte[] data_SaunaStateTimeTemp;
    // 数据点"FMBT_StateFreqVol"对应的存储数据
    private static byte[] data_FMBT_StateFreqVol;
    // 数据点"FMBT_16_Freq"对应的存储数据
    private static byte[] data_FMBT_16_Freq;

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "myapp";
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        fullScreen(this);
    }

    @Override
    public void onBackPressed() {
//        MainApplication.getOpenNativePackage().openNativeModule.jumpToNativeView();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    /**
     * 通过设置全屏，设置状态栏透明
     *
     * @param activity
     */
    protected void fullScreen(Activity activity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                //5.x开始需要把颜色设置透明，否则导航栏会呈现系统默认的浅灰色
                Window window = activity.getWindow();
                View decorView = window.getDecorView();
                //两个 flag 要结合使用，表示让应用的主体内容占用系统状态栏的空间
                int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
                decorView.setSystemUiVisibility(option);
                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                window.setStatusBarColor(Color.TRANSPARENT);
                //导航栏颜色也可以正常设置
//                window.setNavigationBarColor(Color.TRANSPARENT);
            } else {
                Window window = activity.getWindow();
                WindowManager.LayoutParams attributes = window.getAttributes();
                int flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
                int flagTranslucentNavigation = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
                attributes.flags |= flagTranslucentStatus;
//                attributes.flags |= flagTranslucentNavigation;
                window.setAttributes(attributes);
            }
        }
    }

}
